package com.ys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ys.dao.StuDao;
import com.ys.dto.StuDto;
import com.ys.entity.Stu;
import com.ys.service.StuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName StuServiceImpl
 * @Author 1628994918qq.com
 * @Date 2022/11/25 17:12
 */
@Service
@Slf4j
public class StuServiceImpl implements StuService {
    @Autowired
    private StuDao stuDao;
    @Override
    public List<Stu> getStu() {
        List<Stu> stus = stuDao.selectList(null);
        return stus;
    }

    @Override
    public Stu getStuById(Integer id) {
        Stu stu = stuDao.selectById(id);
        return stu;
    }

    @Override
    public Page<Stu> getStuByPage(Page page) {
        QueryWrapper<Stu> wrapper = new QueryWrapper<>();
        Page<Stu> page1 = stuDao.selectPage(page, wrapper);
        return page1;
    }

    @Override
    public List<Stu> selectStuByIds(List<Integer> ids) {
        List<Stu> stus = stuDao.selectBatchIds(ids);
        return stus;
    }

    @Override
    public List<Stu> selectByMap(Map<String, Object> columnMap) {
        List<Stu> stus = stuDao.selectByMap(columnMap);
        return stus;
    }

    @Override
    public List<Stu> selectList() {
        QueryWrapper<Stu> queryWrapper = new QueryWrapper<>();
        //queryWrapper.like("stu_name","闫");
        List<Stu> stus = stuDao.selectList(queryWrapper);
        return stus;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertStus(StuDto stuDto) {
        log.info("线程-" + Thread.currentThread().getId() + "在执行写入");
        int i = stuDao.insert(stuDto);
        log.info("线程-" + Thread.currentThread().getId() + "执行完成");
        if (i>0){
            return 1;
        }
        return 0;
    }

    @Override
    public int selectAbs() {
        int i = stuDao.selectAbs();
        return i;
    }

    @Override
    public int insertStu(Map<String, Object> map) {
        int i = stuDao.insertStu(map);
        if (i>0){
            return i;
        }else {
            return i;
        }
    }

    @Override
    public Stu update111(int id) {
        String s = "id = 1061416962";
        Stu stu = stuDao.update11(s);
        return stu;
    }

    @Override
    public Map<String, Object> selectAll() {
        Map<String, Object> map = stuDao.selectAll();
        return map;
    }

    @Override
    public List<Map<String, Object>> selectListAll() {
        List<Map<String, Object>> mapList = stuDao.selectListAll();
        return mapList;
    }

    @Override
    public Stu selectStuByStuId(String stuId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("stu_id",stuId);
        Stu stu = stuDao.selectOne(wrapper);
        return stu;
    }
}
